package com.aotain.nyx.sqlinjection;

import org.apache.flink.api.common.functions.ReduceFunction;
import org.apache.flink.api.java.tuple.Tuple2;


public class SQLInjectionReduce implements ReduceFunction<Tuple2<String, SQLInjectionTuple>>{

	/**
	 * 
	 */
	private static final long serialVersionUID = -3770526391827164982L;

	@Override
	public Tuple2<String, SQLInjectionTuple> reduce(
			Tuple2<String, SQLInjectionTuple> arg0,
			Tuple2<String, SQLInjectionTuple> arg1) throws Exception {
		// TODO Auto-generated method stub
		//累加key条件下发现SQL注入的次数
		SQLInjectionTuple AandRet = arg0.f1;
		SQLInjectionTuple B = arg1.f1;
		
		AandRet.setCounter(AandRet.getCounter() + B.getCounter());
		AandRet.setUpStreamOctets(AandRet.getUpStreamOctets() + B.getUpStreamOctets());
		AandRet.setUpStreamPacket(AandRet.getUpStreamPacket() + B.getUpStreamPacket());
		
		Tuple2<String, SQLInjectionTuple> ret = new Tuple2<String, SQLInjectionTuple>(arg0.f0,AandRet);
		
		return ret;
	}

}
